<h3>Locum Login</h3>
<div id="popup_top"></div> 
<div id="popup_mid">
	<?php echo $form->create('User',array('action'=>'register','class'=>'splashForm','id'=>'pharmacyReg1'));?>
	<span class="error errors-register">&nbsp;</span>
	<table border="0" cellspacing="0" cellpadding="0">
	        <tr>
	            <td><?php echo $form->input('Username',array('label'=>false,'div'=>'','value'=>'Username')); ?></td>
	        </tr>
	        <tr><td>
	        	<input type="text" name="Userfakepassword" id="Userfakepassword" value="Password" onfocus="pwdFocus()" />
	        	<?php echo $form->password('Password',array('label'=>false,'div'=>'', 'style'=>'display:none;')); ?>
	        </td></tr>
	        <tr><td>
	        	<?php echo $form->hidden('UserType',array('value'=>$_REQUEST['UserType'])); ?>
	        	<input type="button" value="Login" class="pharmacyBtn" />
	        </td></tr>
	</table>
	<?php 
	    echo $form->end();
	?> 
	<div style="clear:both;"></div>
</div>
<div id="popup_bottom"></div>
<script>
	function pwdFocus() {
	    $('#Userfakepassword').hide();
	    $('#UserPassword').show();
	    $('#UserPassword').focus();
	}
    function v_fRemoveErrors()
    {
        $('#UserUsername').focus(function(){
             $('#UserUsername').parent().find('span').remove();
             if(  $(this).val() == 'Username' )
             	$(this).val('');
        });
        
        $('#UserPassword').focus(function(){
             $('#UserPassword').parent().find('span').remove();
        });
    }

    function v_fValidate()
    {
    	var Username = $('#UserUsername').val();
    	if( Username == "" || Username == "Username" ){
        	alert('Please enter Username');
        	$('#UserUsername').focus();
        	return false;
    	}
    	var Password = $('#UserPassword').val();
    	if( Password == "" ){
        	alert('Please enter Password');
        	pwdFocus();
        	return false;
    	}
    	return true;
    }
    
    $(document).ready(function(){
       v_fRemoveErrors();
       $('.pharmacyBtn').click(function(){
    	   if ( !v_fValidate())
        	   return false;
           $.ajax({
                type: 'POST',
                url: 'users/login',
                data:$('form#pharmacyReg1').serializeArray(),
                dataType: 'json',
                success: function(data){ 
                    if(data.success == 'faild')
                    {
                        $(".error").show();
                        $(".error").html('');
                        $(".error").html(data.message);
                    }
                    else
                    {
                        var User = data.User;
                      if( User.UserType == 1 )
                          if(User.IsFirstLogin == 1)
							window.location = 'locums/edit/' + User.id;
                          else
							window.location = 'locums/view/' + User.id;
						
                      else if ( User.UserType == 2 )
                    	  window.location = 'pharmacies/view/' + User.id;
                      else
                    	  window.location = 'stores/view/' + User.id;
                    }
                },
                error: function(message){
                   new Messi(
						 'Network connection errors!', 
						 {
							 title: 'Errors', 
							 modal: true
						  }
						 );
                }
             });
       });
    });
</script>